package org.example.api.source;


import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.example.api.bean.SensorReading;

import java.util.Arrays;
import java.util.List;

/**
 * @author huangqihan
 * @date 2021/2/18
 */
public class SourceFromCollection {

    public static void main(String[] args) throws Exception {

        // 创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        // 创建数据源
        List<SensorReading> sensorReadings = Arrays.asList(
                new SensorReading("sensor_1", 1547718199L, 35.8),
                new SensorReading("sensor_3", 1547728199L, 15.8),
                new SensorReading("sensor_6", 1547728199L, 6.7),
                new SensorReading("sensor_10", 1547738199L, 37.8)
        );

        DataStreamSource<SensorReading> sensorReadingDataStreamSource = env.fromCollection(sensorReadings);
        DataStreamSource<Integer> integerDataStreamSource = env.fromElements(1, 2, 3, 4, 5);

        sensorReadingDataStreamSource.print("bean");
        integerDataStreamSource.print("int");

        env.execute();
    }
}
